<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    var arr=[
            [1,2,[31,32]],
            [4,5,[61,62,[631,632]]],
            [7,[81,82,[831,832,833,[8341,8342,8343,[83441,83442,83443]]]]],
            9,0
    ];

    function flatten(arr){
        var last=[],r;
        for(var i= 0,j=arr.length;i<j;i++){
            if(arr[i].length){
                r=flatten(arr[i]);
                last=last.concat(r);
            }else{
                last.push(arr[i]);
            }
        }
        return last;
    }

    console.log(flatten(arr));

</script>
</body>
</html>